<!DOCTYPE html><html><head><title>README</title><link href="http://www.jboss.org/jdf/stylesheets/documentation.css" rel="stylesheet"></link><link href="http://www.jboss.org/jdf/stylesheets/pygments.css" rel="stylesheet"></link></head><body>
<h1><a id="ejbtimer-ejb-timers-example-schedule-and-timeout" class="anchor" href="#ejbtimer-ejb-timers-example-schedule-and-timeout"><span class="anchor-icon"></span></a>ejb-timer: EJB Timers example - @Schedule and @Timeout</h1>

<p>Author: Ondrej Zizka <a href="mailto:ozizka@redhat.com">ozizka@redhat.com</a><br/>
Level: Beginner<br/>
Technologies: EJB 3.1 Timer<br/>
Summary: Demonstrates how to use EJB 3.1 Timer (@Schedule and @Timeout) with the JBoss AS server.<br/>
Target Product: EAP<br/>
Product Versions: EAP 6.1, EAP 6.2<br/>
Source: <a href="https://github.com/jboss-developer/jboss-eap-quickstarts/">https://github.com/jboss-developer/jboss-eap-quickstarts/</a>  </p>

<h2><a id="what-is-it" class="anchor" href="#what-is-it"><span class="anchor-icon"></span></a>What is it?</h2>

<p>Demonstrates how to use EJB 3.1 Timer (@Schedule and @Timeout) with the JBoss AS server.</p>

<p>Features used:</p>

<ul>
<li>Usage of <code>@Schedule</code></li>
<li>Usage of <code>@Timeout</code></li>
</ul>

<h2><a id="system-requirements" class="anchor" href="#system-requirements"><span class="anchor-icon"></span></a>System requirements</h2>

<p>The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 6.1 or later. </p>

<p>All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later.</p>

<h2><a id="configure-maven" class="anchor" href="#configure-maven"><span class="anchor-icon"></span></a>Configure Maven</h2>

<p>If you have not yet done so, you must <a href="../README.html#mavenconfiguration">Configure Maven</a> before testing the quickstarts.</p>

<h2><a id="start-the-jboss-server" class="anchor" href="#start-the-jboss-server"><span class="anchor-icon"></span></a>Start the JBoss Server</h2>

<ol>
<li>Open a command line and navigate to the root of the JBoss server directory.</li>
<li><p>The following shows the command line to start the server:</p>
<div class="highlight"><pre><span class="n">For</span> <span class="n">Linux</span><span class="o">:</span>   <span class="n">JBOSS_HOME</span><span class="o">/</span><span class="n">bin</span><span class="o">/</span><span class="n">standalone</span><span class="p">.</span><span class="n">sh</span>
<span class="n">For</span> <span class="n">Windows</span><span class="o">:</span> <span class="n">JBOSS_HOME</span><span class="err">\</span><span class="n">bin</span><span class="err">\</span><span class="n">standalone</span><span class="p">.</span><span class="n">bat</span>
</pre></div></li>
</ol>

<h2><a id="build-and-deploy-the-quickstart" class="anchor" href="#build-and-deploy-the-quickstart"><span class="anchor-icon"></span></a>Build and Deploy the Quickstart</h2>

<p><em>NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See <a href="../README.html#buildanddeploy">Build and Deploy the Quickstarts</a> for complete instructions and additional options.</em></p>

<ol>
<li>Make sure you have started the JBoss Application Server as described above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>Type this command to build and deploy the archive:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">clean</span> <span class="n">install</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="o">:</span><span class="n">deploy</span>
</pre></div></li>
</ol>

<p>This will deploy <code>target/jboss-ejb-timer.war</code> to the running instance of the server.
To undeploy, use</p>
<div class="highlight"><pre>    <span class="n">mvn</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="o">:</span><span class="n">undeploy</span>
</pre></div>
<h2><a id="access-the-application" class="anchor" href="#access-the-application"><span class="anchor-icon"></span></a>Access the application</h2>

<p>This application only prints messages to stdout.
To see it working, check the server log. You should see similar output:</p>
<div class="highlight"><pre><span class="p">...</span>
<span class="mi">18</span><span class="o">:</span><span class="mi">33</span><span class="o">:</span><span class="mi">36</span><span class="p">,</span><span class="mo">004</span> <span class="n">INFO</span>  <span class="p">[</span><span class="n">stdout</span><span class="p">]</span> <span class="p">(</span><span class="n">EJB</span> <span class="k">default</span> <span class="o">-</span> <span class="mi">7</span><span class="p">)</span> <span class="n">Hi</span> <span class="n">from</span> <span class="n">the</span> <span class="n">EJB</span> <span class="n">timer</span> <span class="n">example</span><span class="o">!</span>
<span class="mi">18</span><span class="o">:</span><span class="mi">33</span><span class="o">:</span><span class="mi">38</span><span class="p">,</span><span class="mo">003</span> <span class="n">INFO</span>  <span class="p">[</span><span class="n">stdout</span><span class="p">]</span> <span class="p">(</span><span class="n">EJB</span> <span class="k">default</span> <span class="o">-</span> <span class="mi">8</span><span class="p">)</span> <span class="n">Hi</span> <span class="n">from</span> <span class="n">the</span> <span class="n">EJB</span> <span class="n">timer</span> <span class="n">example</span><span class="o">!</span>
<span class="mi">18</span><span class="o">:</span><span class="mi">33</span><span class="o">:</span><span class="mi">40</span><span class="p">,</span><span class="mo">002</span> <span class="n">INFO</span>  <span class="p">[</span><span class="n">stdout</span><span class="p">]</span> <span class="p">(</span><span class="n">EJB</span> <span class="k">default</span> <span class="o">-</span> <span class="mi">9</span><span class="p">)</span> <span class="n">Hi</span> <span class="n">from</span> <span class="n">the</span> <span class="n">EJB</span> <span class="n">timer</span> <span class="n">example</span><span class="o">!</span>
<span class="mi">18</span><span class="o">:</span><span class="mi">33</span><span class="o">:</span><span class="mi">42</span><span class="p">,</span><span class="mo">002</span> <span class="n">INFO</span>  <span class="p">[</span><span class="n">stdout</span><span class="p">]</span> <span class="p">(</span><span class="n">EJB</span> <span class="k">default</span> <span class="o">-</span> <span class="mi">10</span><span class="p">)</span> <span class="n">Hi</span> <span class="n">from</span> <span class="n">the</span> <span class="n">EJB</span> <span class="n">timer</span> <span class="n">example</span><span class="o">!</span>
<span class="mi">18</span><span class="o">:</span><span class="mi">33</span><span class="o">:</span><span class="mi">44</span><span class="p">,</span><span class="mo">003</span> <span class="n">INFO</span>  <span class="p">[</span><span class="n">stdout</span><span class="p">]</span> <span class="p">(</span><span class="n">EJB</span> <span class="k">default</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="n">Hi</span> <span class="n">from</span> <span class="n">the</span> <span class="n">EJB</span> <span class="n">timer</span> <span class="n">example</span><span class="o">!</span>
<span class="mi">18</span><span class="o">:</span><span class="mi">33</span><span class="o">:</span><span class="mi">46</span><span class="p">,</span><span class="mo">004</span> <span class="n">INFO</span>  <span class="p">[</span><span class="n">stdout</span><span class="p">]</span> <span class="p">(</span><span class="n">EJB</span> <span class="k">default</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="n">Hi</span> <span class="n">from</span> <span class="n">the</span> <span class="n">EJB</span> <span class="n">timer</span> <span class="n">example</span><span class="o">!</span>
<span class="mi">18</span><span class="o">:</span><span class="mi">33</span><span class="o">:</span><span class="mi">48</span><span class="p">,</span><span class="mo">003</span> <span class="n">INFO</span>  <span class="p">[</span><span class="n">stdout</span><span class="p">]</span> <span class="p">(</span><span class="n">EJB</span> <span class="k">default</span> <span class="o">-</span> <span class="mi">3</span><span class="p">)</span> <span class="n">Hi</span> <span class="n">from</span> <span class="n">the</span> <span class="n">EJB</span> <span class="n">timer</span> <span class="n">example</span><span class="o">!</span>
<span class="p">...</span>
</pre></div>
<p>The parentheses contain name of thread executing the particular invocation.
There are pre-created threads in thread pool, and they are rotated. Hence the changing number.</p>

<h2><a id="undeploy-the-archive" class="anchor" href="#undeploy-the-archive"><span class="anchor-icon"></span></a>Undeploy the Archive</h2>

<ol>
<li>Make sure you have started the JBoss Server as described above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>When you are finished testing, type this command to undeploy the archive:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="o">:</span><span class="n">undeploy</span>
</pre></div></li>
</ol>

<h2><a id="debug-the-application" class="anchor" href="#debug-the-application"><span class="anchor-icon"></span></a>Debug the Application</h2>

<p>If you want to debug the source code or look at the Javadocs of any library in the project, 
run either of the following commands to pull them into your local repository. The IDE should then detect them.</p>
<div class="highlight"><pre>    <span class="n">mvn</span> <span class="n">dependency</span><span class="o">:</span><span class="n">sources</span>
    <span class="n">mvn</span> <span class="n">dependency</span><span class="o">:</span><span class="n">resolve</span> <span class="o">-</span><span class="n">Dclassifier</span><span class="o">=</span><span class="n">javadoc</span>
</pre></div></body></html>
